package jsoundcapturever2;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MainTestGUI extends JFrame {

	private JPanel contentPane;
	JPanel panel;
	MyRecorder mr;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainTestGUI frame = new MainTestGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MainTestGUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 699, 472);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(null);
		setContentPane(contentPane);
		// ** recorder **//
		mr = new MyRecorder(true);
		panel = new JPanel(new BorderLayout());
		panel.setBounds(10, 11, 564, 412);
		try {
			panel.add(mr.getSamplingGraph());
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		contentPane.add(panel);

		JButton btnNewButton = new JButton("Rec");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					mr.startRecord();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		btnNewButton.setBounds(584, 11, 89, 23);
		contentPane.add(btnNewButton);

		JButton btnNewButton_1 = new JButton("Play");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				mr.playRecorded();
			}
		});
		btnNewButton_1.setBounds(584, 79, 89, 23);
		contentPane.add(btnNewButton_1);

		// JButton btnDraw = new JButton("Draw");
		// btnDraw.addActionListener(new ActionListener() {
		// public void actionPerformed(ActionEvent arg0) {
		// // SamplingGraph sg = new SamplingGraph(mr.getFormat(),
		// // mr.extractFloatDataFromAudioInputStream(), mr.getDuration());
		// // sg.setSize(300, 200);
		// // panel.add(sg);
		// sg.createWaveForm(mr.getFormat(),
		// mr.extractFloatDataFromAudioInputStream(), mr.getDuration());
		//
		// }
		// });
		// btnDraw.setBounds(302, 129, 89, 23);
		// contentPane.add(btnDraw);

		JButton btnStop = new JButton("Stop");
		btnStop.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				mr.stopRecord();
			}
		});
		btnStop.setBounds(584, 45, 89, 23);
		contentPane.add(btnStop);

	}
}
